
	<script type="text/javascript">
		function doGen() {
			addProgress("Generation lauched!");
			addProgress("Generating erosion ...!");

			// start generation
			doFirstStep();
		}
		

		function addProgress(text) {
			var newDiv = document.createElement("div");
			newDiv.appendChild(document.createTextNode(text));
			newDiv.setAttribute("class", "progressInfo");
			document.getElementById("progress").appendChild(newDiv);
		}
		
		function addMapPreview(){
			document.getElementById("mapPreview").setAttribute("src", "/static/images/map1.bmp");
		}
		
		function check(step,callback){
			var req = new XMLHttpRequest();
			var url = "check?step="+step;
			req.open("GET", url, true);
			req.onreadystatechange=function(){
				if(req.readyState == 4){
					if(req.status == 200){
						callback();
					}else{
						showError(req.status,req.statusText);
					}
				}
			}
			req.send();
		}

		function doFirstStep() {
			// Call will return when first step is complete
			check(1,doSecondStep);
		}
		
		function doSecondStep(){
			// Call will return when first step is complete
			addProgress("DONE");
			addProgress("Generating rivers ...");
			check(2,doThirdStep);
		}
		function doThirdStep(){
			// Call will return when first step is complete
			addProgress("DONE");
			addProgress("Generating biomes ...");
			check(3,doFourthStep);
		}
		function doFourthStep(){
			// Call will return when first step is complete
			addProgress("DONE");
			addProgress("Exporting map ...");
			check(100,doLastStep);
		}
		
		function doLastStep(){
			addProgress("DONE");
			addProgress("Generation finished!");
			addMapPreview();
		}
		
		function showError(errorCode,errorText){
			addProgress("ERROR, request returned with error code : "+errorCode+" "+errorText);
		}
		
	</script>
	
	<a class="laucher" onclick="doGen()">GOOOOOOOOOOOOO</a>

	<div id="progress"></div>
	
	<img id="mapPreview" alt="Generating..." src="/static/images/loading.gif">
	
	<!-- Start the script -->
	<script type="text/javascript">
		doGen();
	</script>